package com.xj.edu.hotel.service.serviceImpl;

import com.xj.edu.hotel.domain.HisOrder;
import com.xj.edu.hotel.domain.Order;
import com.xj.edu.hotel.mapper.HisOrderMapper;
import com.xj.edu.hotel.mapper.OrderMapper;
import com.xj.edu.hotel.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private HisOrderMapper hisOrderMapper;

    @Override
    public int delOrder(String id) {
       return orderMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int editOrder(Order order) {
        return orderMapper.updateByPrimaryKeySelective(order);
    }

    @Override
    public List<Order> findAllOrder() {
       List<Order> orders = orderMapper.selectAll();
        return orders;
    }

    @Override
    public Order findByIdOrder(String id) {
        Order order = orderMapper.findById(id);
        return order;
    }

    @Override
    public List<Order> findOrderByHotelId(String id) {
        return orderMapper.findOrderByHotelId(id);
    }

    /**
     *  用户订单列表
     */
    @Override
    public List<Order> userorder(String id) {
        List<Order> orders = orderMapper.findUserOrder(id);
        return orders;
    }
    /**
     *  用户订单详情
     */
    @Override
    public Order orderitem(String id) {
        Order order = orderMapper.findOrderitem(id);
        return order;
    }
    /**
     *  存入历史订单
     */
    @Override
    public int insertHisOrder(HisOrder hisOrder) {
        return hisOrderMapper.insertSelective(hisOrder);
    }
    /**
     *  历史订单列表
     */
    @Override
    public List<HisOrder> findHisorder(String id) {
        List<HisOrder> hisorders = hisOrderMapper.findHisorder(id);
        return hisorders;
    }

    @Override
    public List<HisOrder> findAllHisOoder() {
        return hisOrderMapper.findAllHisOrder();
    }
    /**
     *  存入新建订单
     */
    @Override
    public int insertOrder(Order Order) {
        return orderMapper.insertSelective(Order);
    }

}
